package org.wutopia.labcloud.domain.order.controller;

import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.wutopia.labcloud.domain.order.controller.vo.input.OrderCreateOrderInputVO;
import org.wutopia.labcloud.domain.order.controller.vo.input.OrderPayInputVO;
import org.wutopia.labcloud.domain.order.service.OrderService;
import org.wutopia.labcloud.library.common.base.CodedMessage;
import org.wutopia.labcloud.library.common.base.CommonResponse;

@RestController
@AllArgsConstructor
@RequestMapping("/order")
public class OrderController {


    private OrderService orderService;

    @PostMapping("/create")
    public ResponseEntity<CodedMessage<String>> createOrder(@RequestBody OrderCreateOrderInputVO vo) throws Exception {

        orderService.createOrder(vo);

        return CommonResponse.success();
    }


    @PostMapping("/pay")
    public ResponseEntity<CodedMessage<String>> pay(@RequestBody OrderPayInputVO vo) throws Exception {

        orderService.pay(vo);

        return CommonResponse.success();
    }

    @PostMapping("/cancel")
    public ResponseEntity<CodedMessage<String>> cancel(@RequestBody Long orderId) throws Exception {

        orderService.cancel(orderId);
        return CommonResponse.success();
    }

    @PostMapping("/confirmed")
    public ResponseEntity<CodedMessage<String>> confirmed(@RequestBody Long orderId) throws Exception {

        orderService.cancel(orderId);
        return CommonResponse.success();
    }
}
